import VueRouter from "vue-router"
import Vue from "vue"
// 使用路由插件
Vue.use(VueRouter)

import Home from '@/pages/home'
import Login from '@/pages/login'
import Register from '@/pages/register'
import Search from '@/pages/search'

let originPush = VueRouter.prototype.push
let originReplace = Vue.prototype.originReplace

VueRouter.prototype.push = function (location,res,rej) {
    if (res && rej ) {
        originPush.call(this,location,res,rej)
    } else {
        originPush.call(this,location,()=>{},()=>{})
    }
}

VueRouter.prototype.replace = function(location ,res,rej) {
    if (res && rej) {
        originReplace.call(this,location,res,rej)
    } else {
        originReplace.call(this,location,() => {},() => {})
    }
}


//第二步:暴露VueRouter类的实例
// 对外暴露一个路由器
export default new VueRouter({
    routes: [
        {
            path:'/home',
            component: Home,
            meta: {showFooter:true}
        },
        {
            path: '/login',
            component: Login,
            meta: {showFooter:false}
        },
        {
            path: '/register',
            component: Register,
            meta: {showFooter:false}
        },
        {
            name: 'search',
            path: '/search/:keyword',
            component: Search,
            meta: {showFooter:true}
        },
        // 路由重定向
        {
            path: '*',
            redirect: '/home'
        }
    ]
})
